package com.wlstudy.leyou.common.advice;

import com.wlstudy.leyou.common.exception.LyException;
import com.wlstudy.leyou.common.vo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 通用异常处理
 * 
 * @author wl 
 */
@ControllerAdvice
public class CommonExceptionHandler {
    
    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handleException(LyException e) {
        return ResponseEntity.status(e.getExceptionEnum().getCode()).body(new ExceptionResult(e.getExceptionEnum()));
    }
}
